<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Victor
 * Date: 04.12.11
 * Time: 14:16
 * To change this template use File | Settings | File Templates.
 */
require_once __LIBRARY__ . DS . 'Core' . DS . 'Loader.php';
class Core_Bootstrap
{
    /**
     * @var bool
     */
    private $front = null;


    public function loadApp()
    {

        $loader = Core_Loader::getInstance();

        $loader->register();       //remove

        $paths = array(__BASEPATH__ . DS . 'lib',
                       __BASEPATH__ . DS . 'controllers',
                       __BASEPATH__ . DS . 'models',
                       __BASEPATH__ . DS . 'layouts');
        Core_Loader::addIncludePath($paths);
        // set_include_path(implode(PATH_SEPARATOR, $paths));  */

        $twigLoader = new Twig_Loader_Filesystem(Core_Loader::$includePath);

        $twig = new Twig_Environment($twigLoader, array(
                                                       'debug' => true));

        $dm = DataModule::getInstance();
        $auth = new Auth_Auth2($dm);


        $registry = Core_Registry::getInstance();
        $registry->twig = $twig;
        $registry->dm = $dm;
        $registry->auth = $auth;
        $routes = include_once(__LIBRARY__ . DS . 'Core' . DS . 'routes.php');

        $frontController = Core_FrontController::getInstance();
        $frontController->setRoutes($routes);
        $frontController->registry = $registry;
        $this->front = $frontController;

    }

    /**
     * @return Core_FrontController|null
     */
    public function getFrontController()
    {
        return $this->front;
    }

}
